package sg.simple.snmp.provider.impl;

import isnmp.ui.dto.CPUInfo;
import isnmp.ui.dto.DeviceInfo;
import isnmp.ui.dto.StorageInfo;
import isnmp.ui.dto.MachineInfo;
import isnmp.ui.dto.ProgramInfo;
import isnmp.ui.dto.NetworkInfo;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import sg.simple.snmp.provider.IpDiscoveryCallback;
import sg.simple.snmp.provider.NetMapException;
import sg.simple.snmp.provider.SimpleSNMPQueries;

public class MockSimpleSNMPQueriesImpl implements SimpleSNMPQueries {

	@Override
	public void listIPsAsync(final String subnet, final int timeoutInMillies,
			final IpDiscoveryCallback callback) throws NetMapException {

		List<String> ips = new ArrayList<String>();

		for (int i = 0; i < 10; i++) {
			callback.onActiveIpDiscovered(String.format("%d.%d.%d.%d",
					createRandomIPFragment(), createRandomIPFragment(),
					createRandomIPFragment(), createRandomIPFragment()));
		}

	}

	@Override
	public MachineInfo getMachineInfo(String ipAddress,
			int timeoutInMillies, String community) throws NetMapException {

		return new MachineInfo(ipAddress);
	}

	@Override
	public void shutdownMachine(String ipAddress) throws NetMapException {

		System.out.println("shutting down: " + ipAddress);
	}

	@Override
	public void restartMachine(String ipAddress) throws NetMapException {

		System.out.println("restarting: " + ipAddress);

	}

	@Override
	public void blockMachine(String ipAddress) throws NetMapException {

		System.out.println("blocking: " + ipAddress);

	}

	private int createRandomIPFragment() {
		Random rnd = new Random();
		return Math.abs(rnd.nextInt() % 128);
	}

	@Override
	public boolean isMachineAlive(String ipAddress, int timeoutInMillies) {

		return false;
	}

	@Override
	public List<CPUInfo> getCPUInfo(String ipAddress, int timeoutInMillies,
			String community) throws NetMapException {
		List<CPUInfo> list = new ArrayList<CPUInfo>();
		return list;
	}

	@Override
	public List<ProgramInfo> getProgramInfo(String ipAddress,
			int timeoutInMillies, String community) throws NetMapException {

		List<ProgramInfo> list = new ArrayList<ProgramInfo>();
		return list;
	}

	@Override
	public List<NetworkInfo> getNeworkInfo(String ipAddress,
			int timeoutInMillies, String community) throws NetMapException {
		List<NetworkInfo> list = new ArrayList<NetworkInfo>();
		return list;
	}

	@Override
	public List<StorageInfo> getStorageInfo(String ipAddress,
			int timeoutInMillies, String community) throws NetMapException {
		List<StorageInfo> list = new ArrayList<StorageInfo>();
		return list;
	}

	@Override
	public List<DeviceInfo> getDeviceInfo(String ipAddress,
			int timeoutInMillies, String community) throws NetMapException {
		List<DeviceInfo> list = new ArrayList<DeviceInfo>();
		return list;
	}

}
